class Task62:
    def run(self, n, m):
        # f(1, m) = 0
        # f(n, m) = (f(n-1, m) + m) % n
        f = 0
        for k in range(2, n + 1):
            f = (f + m) % k
        return f
